#include "conf.h"

void change_video_tables(int a, int b){
}


void  set_quality(int *x){ // -17 highest; +12 lowest
 if (conf.video_mode) *x=12-((conf.video_quality-1)*(12+17)/(99-1));
}

void __attribute__((naked,noinline)) movie_record_task(){ 

 asm volatile(
		"STMFD	SP!, {R2-R8,LR}\n"
		"LDR	R8, =0x425\n"
		"LDR	R7, =0x2710\n"
		"LDR	R4, =0x2BF8\n"
		"MOV	R6, #0\n"
		"MOV	R5, #1\n"
"loc_FF87904C:\n" //				; CODE XREF: task_MovieRecord+140j\n"
		"LDR	R0, [R4,#0x18]\n"
		"MOV	R2, #0\n"
		"ADD	R1, SP,	#4\n"			// previous "ADD	R1, SP,	#0x4\n"	
		"BL	sub_FF838318\n"
		"LDR	R2, =0xFF877608\n"
		"LDR	R0, [R4,#0xB4]\n"
		"MOV	R3, R8\n"
		"MOV	R1, R7\n"
		"BL	sub_FF838C14\n"
		"LDR	R0, [R4,#0x20]\n"
		"CMP	R0, #0\n"
		"BNE	loc_FF87914C\n"
		"LDR	R0, [SP,#4]\n"  //"LDR	R0, [SP,#0x4]\n"
		"LDR	R1, [R0]\n"
		"SUB	R1, R1,	#2\n"
		"CMP	R1, #0xB\n"
		"ADDLS	PC, PC,	R1,LSL#2\n"
		"B	loc_FF87914C\n"
"loc_FF879094:	B	loc_FF8790F4\n"
"loc_FF879098:	B	loc_FF87910C\n"
"loc_FF87909C:	B	loc_FF87911C\n"
"loc_FF8790A0:	B	loc_FF879124\n"
"loc_FF8790A4:	B	loc_FF8790FC\n"
"loc_FF8790A8:	B	loc_FF87912C\n"
"loc_FF8790AC:	B	loc_FF879104\n"
"loc_FF8790B0:	B	loc_FF87914C\n"
"loc_FF8790B4:	B	loc_FF87913C\n"
"loc_FF8790B8:	B	loc_FF879144\n"
"loc_FF8790BC:	B	loc_FF879134\n"
"loc_FF8790C0:	B	loc_FF8790C4\n"
"loc_FF8790C4:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"LDR	R0, =0xFF878CE0\n"
		"STR	R6, [R4,#0x34]\n"
		"STR	R0, [R4,#0x9C]\n"
		"LDR	R0, =0xFF877B20\n"
		"LDR	R2, =0xFF877B24\n"
		"STR	R0, [R4,#0xA0]\n"
		"LDR	R0, =0xFF877C34\n"
		"LDR	R1, =0x385FC\n" // changed from 385DC to 385FC
		"STR	R6, [R4,#0x24]\n"
		"BL	sub_FF84EE4C\n"
		"STR	R5, [R4,#0x38]\n"
		"B	loc_FF87914C\n" 

"loc_FF8790F4:\n" //				; CODE XREF: task_MovieRecord+58j\n"
//		"BL      unlock_optical_zoom\n" //  + already unlocked in SX20
		"BL	sub_FF878E08\n"
		"B	loc_FF87914C\n"
"loc_FF8790FC:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		//"BL	sub_FF878924\n"
				"BL	sub_FF878924_my\n"	// "BL	sub_FF878924_my\n" // what is this?
		"B	loc_FF87914C\n"
"loc_FF879104:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF87937C\n"
		"B	loc_FF87914C\n"
"loc_FF87910C:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"LDR	R0, [R4,#0x38]\n"
		"CMP	R0, #5\n"
		"STRNE	R5, [R4,#0x28]\n"
		"B	loc_FF87914C\n"
"loc_FF87911C:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF878624\n"
		"B	loc_FF87914C\n"
"loc_FF879124:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF8782D4\n"
		"B	loc_FF87914C\n"
"loc_FF87912C:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF877AAC\n"
		"B	loc_FF87914C\n"
"loc_FF879134:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF8792E4\n"
		"B	loc_FF87914C\n"
"loc_FF87913C:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF878198\n"
		"B	loc_FF87914C\n"
"loc_FF879144:\n" //				; CODE XREF: task_MovieRecord+58j\n"
		"BL	sub_FF87807C\n"
		"STR	R5, [R4,#0xDC]\n"
"loc_FF87914C:\n" //				; CODE XREF: task_MovieRecord+44j\n"
		"LDR	R1, [SP,#4]\n"	//"LDR	R1, [SP,#0x4]\n"
		"MOV	R3, #0x460\n"
		"STR	R6, [R1]\n"
		"STR	R3, [SP]\n"
		"LDR	R0, [R4,#0x1C]\n"
		"LDR	R3, =0xFF877608\n"
		"MOV	R2, R7\n"
		"BL	sub_FF838C6C\n"
		"LDR	R0, [R4,#0xB4]\n"
		"BL	sub_FF838804\n"
		"B	loc_FF87904C\n"
 );
}

// done upto here

void __attribute__((naked,noinline)) sub_FF878924_my(){ 
 asm volatile(
		"STMFD	SP!, {R4-R8,LR}\n"
		"SUB	SP, SP,	#0x48\n"
		"MOV	R7, #0\n"
		"LDR	R6, =0x2BF8\n"
		"MOV	R4, R0\n"
		"STR	R7, [SP,#0x38]\n"
		"STR	R7, [SP,#0x30]\n"
		"LDR	R0, [R6,#0x38]\n"
		"CMP	R0, #3\n"
		"MOVEQ	R0, #4\n"
		"STREQ	R0, [R6,#0x38]\n"
		"LDR	R0, [R6,#0x9C]\n"
		"BLX	R0\n"
		"LDR	R0, [R6,#0x38]\n"
		"CMP	R0, #4\n"
		"BNE	loc_FF878A48\n"
		"ADD	R3, SP,	#0x30\n"
		"ADD	R2, SP,	#0x34\n"
		"ADD	R1, SP,	#0x38\n"
		"ADD	R0, SP,	#0x3C\n"
		"BL	sub_FF95BAC0\n"
		"CMP	R0, #0\n"
		"MOV	R5, #1\n"
		"BNE	loc_FF8789A0\n"
		"LDR	R1, [R6,#0x28]\n"
		"CMP	R1, #1\n"
		"BNE	loc_FF878A50\n"
		"LDR	R1, [R6,#0x4C]\n"
		"LDR	R2, [R6,#0x3C]\n"
		"CMP	R1, R2\n"
		"BCC	loc_FF878A50\n"
"loc_FF8789A0:\n" //				; CODE XREF: sub_FF878924+5Cj\n"
		"BL	sub_FF877C74\n"
		"BL	sub_FF8792D0\n"
		"LDR	R0, [R4,#0x1C]\n"
		"ADD	R4, SP,	#0x18\n"
		"ADD	R3, SP,	#0x40\n"
//		"MOVL	R2, 0xFFFFFFFE\n"
		"MVN     R2, #1\n"
		"MOV	R1, #0\n"
		"STMIA	R4, {R0-R3}\n"
		"LDR	R2, [R6,#0x64]\n"
		"LDR	R3, [R6,#0x68]\n"
		"ADD	R1, SP,	#0x44\n"
		"ADD	R4, SP,	#8\n"
		"MOV	R0, #0\n"
		"STMIA	R4, {R0-R3}\n"
		"MOV	R3, #0\n"
		"MOV	R2, #0x40\n"
		"STRD	R2, [SP]\n"
		"LDR	R3, =0x38668\n"
		"MOV	R2, #0\n"
		"MOV	R1, #0\n"
		"BL	sub_FF9188B8\n"
		"LDR	R0, [R6,#0x10]\n"
		"MOV	R1, #0x3E8\n"
		"BL	sub_FF838734\n"
		"CMP	R0, #9\n"
		"BNE	loc_FF878A18\n"
"loc_FF878A08:\n" //				; CODE XREF: sub_FF878924+1ACj\n"
		"BL	sub_FF95BF94\n"
		"MOV	R0, #1\n"
		"STR	R5, [R6,#0x38]\n"
		"B	loc_FF878B78\n" 
"loc_FF878A18:\n" //				; CODE XREF: sub_FF878924+E0j\n"
		"LDR	R0, [SP,#0x40]\n"
		"CMP	R0, #0\n"
		"BEQ	loc_FF878A34\n"
"loc_FF878A24:\n" //				; CODE XREF: sub_FF878924+1B8j\n"
		"BL	sub_FF95BF94\n"
		"MOV	R0, #1\n"
		"STR	R5, [R6,#0x38]\n"
		"B	loc_FF878BA4\n"
"loc_FF878A34:\n" //				; CODE XREF: sub_FF878924+FCj\n"
		"MOV	R0, #1\n"
		"BL	sub_FF918960\n"
		"BL	sub_FF91899C\n"
		"MOV	R0, #5\n"
		"STR	R0, [R6,#0x38]\n"
"loc_FF878A48:\n" //				; CODE XREF: sub_FF878924+3Cj\n"
		"ADD	SP, SP,	#0x48\n"
		"LDMFD	SP!, {R4-R8,PC}\n"
"loc_FF878A50:\n" //				; CODE XREF: sub_FF878924+68j\n"
		"LDR	R12, [SP,#0x38]\n"
		"CMP	R12, #0\n"
		"BEQ	loc_FF878C88\n"
		"STR	R5, [R6,#0x2C]\n"
		"LDR	R0, [R6,#0x4C]\n"
		"LDR	R8, [R4,#0xC]\n"
		"CMP	R0, #0\n"
		"LDRNE	LR, [SP,#0x3C]\n"
		"BNE	loc_FF878AFC\n"
		"LDR	R0, [R4,#0x1C]\n"
		"LDR	R1, [R4,#0x20]\n"
		"ADD	R3, SP,	#0x40\n"
//		"MOVL	R2, 0xFFFFFFFF\n"
		"MVN     R2, #0\n"
		"ADD	LR, SP,	#0x18\n"
		"STMIA	LR, {R0-R3}\n"
		"LDR	R0, [SP,#0x30]\n"
		"LDR	R2, [R6,#0x64]\n"
		"LDR	R3, [R6,#0x68]\n"
		"ADD	R1, SP,	#0x44\n"
		"ADD	LR, SP,	#8\n"
		"STMIA	LR, {R0-R3}\n"
		"LDR	R3, [SP,#0x34]\n"
		"STR	R12, [SP]\n"
		"STR	R3, [SP,#4]\n"
		"LDMIB	R4, {R0,R1}\n"
		"LDR	R3, [SP,#0x3C]\n"
		"MOV	R2, R8\n"
		"BL	sub_FF9188B8\n"
		"LDR	R0, [R6,#0x10]\n"
		"MOV	R1, #0x3E8\n"
		"BL	sub_FF838734\n"
		"CMP	R0, #9\n"
		"BEQ	loc_FF878A08\n"
		"LDR	R0, [SP,#0x40]\n"
		"CMP	R0, #0\n"
		"BNE	loc_FF878A24\n"
		"MOV	R0, #1\n"
		"BL	sub_FF918960\n"
		"LDR	R0, [SP,#0x44]\n"
		"LDR	R1, [SP,#0x3C]\n"
		"ADD	LR, R1,	R0\n"
		"LDR	R1, [SP,#0x38]\n"
		"SUB	R12, R1, R0\n"
"loc_FF878AFC:\n" //				; CODE XREF: sub_FF878924+14Cj\n"
		"LDR	R2, [R6,#0x48]\n"
		"LDR	R0, [R4,#0x1C]\n"
		"LDR	R1, [R4,#0x20]\n"
		"ADD	R3, SP,	#0x40\n"
		"STR	R1, [SP,#0x1C]\n"
		"STR	R0, [SP,#0x18]\n"
		"STR	R3, [SP,#0x24]\n"
		"STR	R2, [SP,#0x20]\n"
		"LDR	R2, [R6,#0x64]\n"
		"LDR	R3, [R6,#0x68]\n"
		"ADD	R1, SP,	#0x44\n"
		"STR	R1, [SP,#0xC]\n"
		"STR	R3, [SP,#0x14]\n"
		"LDR	R3, [SP,#0x34]\n"
		"LDR	R0, [SP,#0x30]\n"
		"STR	R2, [SP,#0x10]\n"
		"STR	R3, [SP,#0x4]\n"
		"STR	R12, [SP]\n"
		"STR	R0, [SP,#0x8]\n"
		"LDMIB	R4, {R0,R1}\n"
		"MOV	R3, LR\n"
		"MOV	R2, R8\n"
		"BL	sub_FF9188B8\n"
		"LDR	R0, [R6,#0x10]\n"
		"MOV	R1, #0x3E8\n"
		"BL	sub_FF838734\n"
		"CMP	R0, #9\n"
		"BNE	loc_FF878B8C\n"
		"BL	sub_FF95BF94\n"
		"MOV	R0, #0\n"
		"STR	R5, [R6,#0x38]\n"
"loc_FF878B78:\n" //				; CODE XREF: sub_FF878924+F0j\n"
		"BL	sub_FF918960\n"
		"MOV	R0, #0xC\n"
		"BL	sub_FF889D1C\n"
		"MOV	R0, #0x90000\n"
		"B	loc_FF878BB4\n"
"loc_FF878B8C:\n" //				; CODE XREF: sub_FF878924+244j\n"
		"LDR	R0, [SP,#0x40]\n"
		"CMP	R0, #0\n"
		"BEQ	loc_FF878BC8\n"
		"BL	sub_FF95BF94\n"
		"MOV	R0, #0\n"
		"STR	R5, [R6,#0x38]\n"
"loc_FF878BA4:\n" //				; CODE XREF: sub_FF878924+10Cj\n"
		"BL	sub_FF918960\n"
		"MOV	R0, #0xC\n"
		"BL	sub_FF889D1C\n"
		"MOV	R0, #0xA0000\n"
"loc_FF878BB4:\n" //				; CODE XREF: sub_FF878924+264j\n"
		"BL	sub_FF897148\n"
		"LDR	R1, [R6,#0x8C]!\n"
		"LDR	R0, [R6,#0xC]\n"
		"BLX	R1\n"
		"B	loc_FF878A48\n"
"loc_FF878BC8:\n" //				; CODE XREF: sub_FF878924+270j\n"
		"MOV	R0, #0\n"
		"BL	sub_FF918960\n"
		"LDR	R0, [R6,#0xDC]\n"
		"CMP	R0, #1\n"
		"BNE	loc_FF878C58\n"
		"LDR	R0, [R6,#0x48]\n"
		"MOV	R1, #0xF\n"
		"BL	sub_FFB38310\n"
		"MOVS	R4, R1\n"
		"STREQ	R7, [R6,#0xDC]\n"
		"BEQ	loc_FF878C58\n"
		"LDR	R5, [SP,#0x3C]\n"
		"MOV	R2, #4\n"
		"ADD	R0, SP,	#0x2C\n"
		"ADD	R1, R5,	#4\n"
		"BL	sub_FFB36624\n"
		"LDR	R0, [SP,#0x2C]\n"
		"MOV	R1, R0,LSR#24\n"
		"AND	R2, R0,	#0xFF0000\n"
		"ORR	R1, R1,	R2,LSR#8\n"
		"AND	R2, R0,	#0xFF00\n"
		"ORR	R1, R1,	R2,LSL#8\n"
		"ORR	R0, R1,	R0,LSL#24\n"
		"BIC	R0, R0,	#0x1E000\n"
		"ORR	R0, R0,	R4,LSL#13\n"
		"MOV	R1, R0,LSR#24\n"
		"AND	R2, R0,	#0xFF0000\n"
		"ORR	R1, R1,	R2,LSR#8\n"
		"AND	R2, R0,	#0xFF00\n"
		"ORR	R1, R1,	R2,LSL#8\n"
		"ORR	R0, R1,	R0,LSL#24\n"
		"STR	R0, [SP,#0x2C]\n"
		"ADD	R0, R5,	#4\n"
		"ADD	R1, SP,	#0x2C\n"
		"MOV	R2, #4\n"
		"BL	sub_FFB366B4\n"
"loc_FF878C58:\n" //				; CODE XREF: sub_FF878924+2B4j\n"
		"LDR	R0, [SP,#0x3C]\n"
		"LDR	R1, [SP,#0x44]\n"
		"BL	sub_FF95BCEC\n"
		"LDR	R0, [R6,#0x48]\n"
		"LDR	R3, =0x2C60\n"    // ->
		"ADD	R1, R0,	#1\n"
		"STR	R1, [R6,#0x48]\n"
		"STR	R3, [SP]\n"
		"LDR	R0, [SP,#0x44]\n"
		"SUB	R3, R3,	#4\n"     // ->
		"MOV	R2, #0xF\n"
		"BL	sub_FF959D70\n"

                "LDR     R0, =0x2C60-4\n" // <----   -4 //+
                "BL      set_quality\n"                 //+
		
"loc_FF878C88:\n" //				; CODE XREF: sub_FF878924+134j\n"
		"LDR	R0, [R6,#0x4C]\n"
		"ADD	R0, R0,	#1\n"
		"STR	R0, [R6,#0x4C]\n"
		"LDR	R1, [R6,#0x74]\n"
		"MUL	R0, R1,	R0\n"
		"LDR	R1, [R6,#0x70]\n"
		"BL	sub_FFB38310\n"
		"MOV	R4, R0\n"
		"BL	sub_FF95BFCC\n"
		"LDR	R1, [R6,#0x6C]\n"
		"CMP	R1, R4\n"
		"BNE	loc_FF878CC4\n"
		"LDR	R0, [R6,#0x30]\n"
		"CMP	R0, #1\n"
		"BNE	loc_FF878CD8\n"
"loc_FF878CC4:\n" //				; CODE XREF: sub_FF878924+390j\n"
		"LDR	R1, [R6,#0x80]\n"
		"MOV	R0, R4\n"
		"BLX	R1\n"
		"STR	R4, [R6,#0x6C]\n"
		"STR	R7, [R6,#0x30]\n"
"loc_FF878CD8:\n" //				; CODE XREF: sub_FF878924+39Cj\n"
		"STR	R7, [R6,#0x2C]\n"
		"B	loc_FF878A48\n"
 );
}

